<?php
/**
 * 矿机
 */
namespace app\api\model;
use app\common\model\Mining as MiningModel;
use app\api\model\MemberMining as MemberMiningModel;

class Mining extends MiningModel
{
    /**
     * 获取矿机列表
     * @param $language 语言
     * @param int[] $where  查询条件
     * @param int $page 页码
     * @param int $limit    每页数量
     * @return array
     * @throws \think\db\exception\DbException
     */
    public static function apiGetList($language,$where = ['type'=>1],$page = 1,$limit = 20){
        $file = 'id';
        $file .= ','.file_language('name',$language);
        $file .= ',currency,total_num,release_num,destruction_num,virtual_destruction,virtual_release,status,type,add_time';

        $data = self::where($where)->field($file)->paginate(['list_rows'=>$limit,'page'=>$page])->order('id desc')->toArray();

        if(!empty($data['data'])){
            foreach ($data['data'] as $k => $v){
                $data['data'][$k]['validity_time'] = bcdiv(bcsub($v['total_num'],bcadd($v['surplus_num'],$v['destruction_num'])),$v['everyday_num']);
            }
        }
        return $data;
    }

//    /**
//     * 购买矿机
//     * @param $mid  用户ID
//     * @param $num    购买数量
//     * @param $money    金额支付
//     * @param $min_id   矿机ID
//     * @return int|mixed|string
//     * @throws \think\db\exception\DataNotFoundException
//     * @throws \think\db\exception\DbException
//     * @throws \think\db\exception\ModelNotFoundException
//     */
//    public static function pay($mid,$num,$money,$min_id){
//        //矿机购入
//        $id = MemberMiningModel::update_mining($mid,$min_id,$num,$money);
//        return $id;
//    }

}